package org.ipower.examsystem.dao.impl;

import java.util.List;
import org.ipower.examsystem.dao.ItemOptionsDao;
import org.ipower.examsystem.domain.ItemOptions;
import org.ipower.examsystem.service.Option;
import org.ipower.examsystem.service.Options;

/**
 *  题目选项数据访问实现类。
 * @author young
 */
public class ItemOptionsDaoImpl extends ModuleGenericDaoImpl<ItemOptions> implements ItemOptionsDao{

    @Override
    public Options loadOptions(String topicsID) {
        Options options = new Options();
        if(topicsID != null && !topicsID.isEmpty()){
            List<ItemOptions> list = this.loadAll("TopicsID", topicsID);
            if(list != null && list.size() > 0){
                for(ItemOptions item : list){
                    Option data = new Option();
                    data.setTitle(item.getTitle());
                    data.setOptionID(item.getOptionID());
                    data.setContent(item.getContent());
                    data.setImgUri(item.getImgUri());
                    data.setOrderNo(item.getOrderNo());
                    options.add(data);
                }
            }
        }
        return options;
    }

    @Override
    public void delete(String topicsID) {
        if(topicsID != null && !topicsID.isEmpty()){
            this.delete("TopicsID", topicsID);
        }
    }
    
}